import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import manageBaseInfoRoutes from './modules/manageBaseInfoRoutes' // 基础信息管理
export const constantRoutes = [
  // 登录页面
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  // 404 页面
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/Dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard', showNav: true }
    }]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...manageBaseInfoRoutes, { path: '*', redirect: '/404' }]
})

const router = createRouter()

// // reset 路由方法
// export function resetRouter() {
//   // 得到一个全新的 router 实例对象
//   const newRouter = createRouter()
//   // 使用新的路由记录覆盖掉老的路由记录
//   router.matcher = newRouter.matcher // reset router
// }

export default router
